package yss.learn2develop.demoservice;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

/**
 * Created by Administrator on 2014/7/26.
 */
public class YssService extends Service {
    @Override
    public IBinder onBind(Intent intent) {
        return myBinder;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                YssService.this.helloService();
            }
        }).start();

        return super.onStartCommand(intent, flags, startId);
    }

    private void helloService() {
        for (int i = 0; i < 200; i++) {
            try {
                Thread.sleep(1000);
                Log.i("yss log", "Service:" + i);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }

    IBinder myBinder = new MyBinder();

    public class MyBinder extends Binder{

        public String helloWorld(String name)
        {
            return "你好";
        }
    }
}
